fix: avoid 502 on long-running agents via non-blocking + polling - #8
Open
LeoMartin-30 wants to merge 3 commits into
Open
fix: avoid 502 on long-running agents via non-blocking + polling#8LeoMartin-30 wants to merge 3 commits into
LeoMartin-30 wants to merge 3 commits into
Conversation
The current Talk-to-Agent flow POSTs with `blocking: true`, which holds
the HTTP connection open until the agent finishes. Agents that call out
to slow tools (Jira, Slack, Google Docs, MCP servers...) routinely take
>30s and the upstream gateway drops the connection, surfacing as
502 Bad Gateway in n8n.
Switch to the pattern used by Dust's own clients: POST returns
immediately with the conversation sId, then we poll GET
/conversations/{id} until the latest agent_message reaches a terminal
status (succeeded, failed, cancelled) or the max-wait deadline elapses.
New Additional Fields:
- Wait For Completion (default true) — turn off to return immediately
with just { conversationId, conversationUrl, userMessage }
- Poll Interval (Ms) (default 1500)
- Max Wait (Ms) (default 120000)
- Full Name — exposed on the message context for Langfuse attribution
Output shape is preserved (`agentMessage` + `conversationUrl` +
`userMessage`) and a new `conversationId` field is added so downstream
nodes can run follow-ups or open the conversation in the Dust UI.
Refs dust-tt#7
Once the agent succeeds, surface three additional fields alongside `agentMessage`: - `chainOfThought` — reasoning trace for thinking-capable models (Sonnet/Opus). Useful to render a "thinking" preview before the final answer or to debug agent runs. - `conversationTitle` — auto-generated title Dust attaches once the agent completes. Handy when archiving conversations downstream. - `rawConversation` — the full conversation object including `content`, `actions`, `citations`, and `generatedFiles`. Lets workflows extract specific tool outputs (e.g. generated file IDs, per-action params) without making a second GET call. All three are additive and backward-compatible with the existing `agentMessage` / `conversationId` / `conversationUrl` / `userMessage` fields.
When an agent generates files during its run — Jira extracts, CSV/HTML
exports, visualizations attached to tool calls — they were buried
inside `rawConversation.content[*].actions[*].generatedFiles` and
required custom n8n expressions to dig out.
Aggregate them into a top-level `generatedFiles` array on the output,
deduplicated by `fileId`, with each entry carrying its title, content
type, snippet, download URL, source tool name and action sId.
When the new `Include Generated File Content` field is on (default
true), the node also downloads each file via
`GET /api/w/{wId}/files/{fileId}?action=download` and inlines:
- `content` (UTF-8 string) for textual content types — text/*, JSON,
XML, HTML, CSV, Markdown, YAML.
- `contentBase64` for binary content.
- `tooLarge: true` for files exceeding the per-file cap (default
10 MB, configurable via `Max Generated File Size (Bytes)`).
- `downloadError` if a single fetch fails, without breaking the
whole node run.
Backward-compatible: when an agent produces no files, the output
array is simply empty.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Switches the Talk To Agent operation from
blocking: trueto non-blocking POST + polling onGET /conversations/{id}. Fixes the502 Bad Gatewaythat systematically happens with agents that take more than ~30 s (Jira / Slack / Google Docs / MCP tool calls), reported in #7.Adds a small set of optional fields and surfaces richer info in the output, all backward-compatible (default behavior still produces an
agentMessage).Closes #7.
What changed
Behavior
/conversationsno longer setsblocking: true/skipToolsValidation: true— the call returns immediately with the conversationsId.GET /conversations/{id}until the latestagent_messagereaches a terminal status (succeeded,failed,cancelled) or the deadline is hit.failed/cancelled, throws with the agent error message + the conversation URL for inspection.New Additional Fields (all optional)
trueconversationIdand let the user poll themselves.1500120000""context.fullNamefield for Langfuse attribution.true10_000_000tooLarge: trueis set.Output additions
conversationId— useful for follow-up messages orconversationTitle.chainOfThought— reasoning trace for thinking-capable models,nullotherwise.conversationTitle— auto-generated title once the agent finishes.rawConversation— full conversation object for downstream extraction.generatedFiles[]— every file produced during the run (across all tool calls), deduped byfileId, with metadata + inlinedcontent/contentBase64(controlled by Include Generated File Content). Empty array when the agent produces none.Test plan
npm run build+npm run lint+.eslintrc.prepublish.jslint — clean.~/.n8n/customvia tarball, loaded byCustomDirectoryLoader, confirmed vian8n export:nodes(Dust / CUSTOM.dust / v1with all 9 Additional Fields in alphabetical order).DATA_WeeklyNotesRewriter(agent that calls Jira / Slack / Google Docs and previously 502'd): node now waits ~3 min and returns the markdown final answer + 3 generated Jira extract files with inlined content.Internal Prompt Writer) — should not regress.Wait For Completion: false— should return immediately withconversationId.